const http = require('http')
const fs = require('fs')
const path = require('path')

const server = http.createServer()

server.on('request', (req, res) => {
  // console.log("请求成功!!!");
  const url = req.url;
  let content = "<h2>404 Not found</h2>";

  const fpath = path.join(__dirname, url);

  if(url === '/' || url === '/index.html') {
    content = "<h2>首页</h2>"
  } else if(url === '/about.html') {
    content = "<h2>关于页面</h2>"
  }

  // 这是编码格式
  res.setHeader('Content-Type', 'text/html; charset=utf-8');
  res.end(content);
})

server.listen(8080, () => {
  console.log("请启动 http://127.0.0.1:8080")
})



